﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace iPodBrake
{
    class Utils
    {
        public static List<Queue> ReadFolder(string Path)
        {
            List<Queue> Lst = new List<Queue>();
            if (Directory.Exists(Path))
            {
                try
                {
                    string[] FoundFiles = Directory.GetFiles(Path);
                    foreach (string file in FoundFiles)
                    {
                        FileInfo fi = new FileInfo(file);
                        if (Array.IndexOf(Extensions, fi.Extension.ToLower()) >= 0)
                        {
                            Queue newQ = new Queue(file);
                            if (!File.Exists(newQ.OutputFileName))
                            {
                                Lst.Add(new Queue(file));
                            }
                        }
                    }
                    string[] FoundSubDirs = Directory.GetDirectories(Path);
                    foreach (string dir in FoundSubDirs)
                    {
                        DirectoryInfo di = new DirectoryInfo(dir);
                        Lst.AddRange(ReadFolder(dir));
                    }

                }
                catch
                {
                }

            }
            return Lst;
        }
        public static string FindHandBrake()
        {
            string fileName = "HandbrakeCLI.exe";
            if (File.Exists("C:\\Program Files\\Handbrake\\" + fileName))
            {
                return "C:\\Program Files\\Handbrake\\" + fileName;
            }
            if (File.Exists("C:\\Program Files (x86)\\Handbrake\\" + fileName))
            {
                return "C:\\Program Files (x86)\\Handbrake\\" + fileName;
            }
            if (File.Exists(System.Reflection.Assembly.GetExecutingAssembly().Location + "\\" + fileName))
            {
                return (System.Reflection.Assembly.GetExecutingAssembly().Location + "\\" + fileName);
            }

            return "";
        }
        public static string[] Extensions = { ".mkv", ".avi" };
    }
}
